package com.olympia.myapp.custom;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.olympia.myapp.R;

public class Dialog_Confirm extends Dialog implements OnClickListener {
	Activity activity;
	ProcessDialogConfirm process;
	TextView txtTitle;
	TextView txtContent;
	Button btnOk;
	Button btnCancel;

	/**
	 * 
	 * @param context
	 */
	public Dialog_Confirm(Context context, String title, String content,
			boolean isShowOk, boolean isShowCancel, ProcessDialogConfirm process) {
		super(context);
		activity = (Activity) context;
		/** 'Window.FEATURE_NO_TITLE' - Used to hide the title */
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		/** Design the dialog in main.xml file */
		setContentView(R.layout.dialog_confirm);
		this.process = process;

		btnOk = (Button) findViewById(R.id.dg_confirm_btnok);
		btnOk.setVisibility(isShowOk ? View.VISIBLE : View.GONE);
		btnCancel = (Button) findViewById(R.id.dg_confirm_btncancel);
		btnCancel.setVisibility(isShowCancel ? View.VISIBLE : View.GONE);
		txtTitle = (TextView) findViewById(R.id.dg_confirm_title);
		if (title.length() > 0) {
			txtTitle.setText(title);
			txtTitle.setVisibility(View.VISIBLE);
		} else
			txtTitle.setVisibility(View.GONE);
		txtContent = (TextView) findViewById(R.id.dg_confirm_content);
		setContent(content);
		btnOk.setOnClickListener(this);
		btnCancel.setOnClickListener(this);
	}

	public void setContent(String content) {
		if (txtContent != null) {
			txtContent.setText(content);
		}
	}

	public void setTextOnButton(String strOk, String strCancel) {
		if (btnOk != null && btnOk.isShown() && strOk.length() > 0)
			btnOk.setText(strOk);
		if (btnCancel != null && strCancel.length() > 0)
			btnCancel.setText(strCancel);
	}

	@Override
	public void onClick(View v) {
		if (v == btnCancel) {
			process.click_Cancel();
			dismiss();
		} else if (v == btnOk) {
			process.click_Ok();
			dismiss();
		}
	}

	public static abstract class ProcessDialogConfirm {
		public abstract void click_Ok();

		public abstract void click_Cancel();
	}
}
